package com.itheima.d2_reflect;

import org.junit.Test;

import java.awt.geom.Rectangle2D;
import java.lang.reflect.Method;

public class Test3Method {
    @Test
    public void testGetMethod() throws Exception {
        Class c=Cat.class;

        Method[] declaredMethods = c.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod.getName()+"==>"
                +declaredMethod.getParameterCount()+"==>"
                +declaredMethod.getReturnType());
        }

        Method run = c.getDeclaredMethod("run");
        System.out.println(run.getName()+"==>"
                +run.getParameterCount()+"==."
                +run.getReturnType());

        Method eat = c.getDeclaredMethod("eat",String.class);
        System.out.println(eat.getName()+"==>"
                +eat.getParameterCount()+"==."
                +eat.getReturnType());

        Cat cat =new Cat();
        run.setAccessible(true);
        Object rs = run.invoke(cat);
        System.out.println(rs);

        eat.setAccessible(true);
        Object rs2 =(String) eat.invoke(cat, "鱼儿");
        System.out.println(rs2);
    }
}
